package com.itheima.produce;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer_WorkQueues {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory=new ConnectionFactory();
        factory.setHost("192.168.17.139");//默认为127.0.0.1
        factory.setPort(5672);
        factory.setVirtualHost("/itcast");//虚拟机
        factory.setUsername("zwy");//用户名
        factory.setPassword("123456");//密码
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        //String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
        //队列名，是否持久化，是否独占，是否自动删除，参数
        channel.queueDeclare("work_queues",true,false,false,null);

        for (int i = 0; i < 10; i++) {
            String body=i+" hello RabbitMQ";
            channel.basicPublish("","work_queues",null,body.getBytes());

        }
        channel.close();
        connection.close();
    }
}
